/**
 * @author wangxiaowei
 * 组织部发文列表
 */
var sort = null;
var grid = null;
var biaoti = '流程跟踪';
function initzuzhibufawenlist(){
	
		 Ext.BLANK_IMAGE_URL=Ext.get('basePath').getValue()+"ajaxFramework/ext-2.1/resources/images/default/s.gif";

Ext.menu.RangeMenu.prototype.icons = {
	  gt: './ajaxFramework/ext-2.1/img/greater_then.png', 
	  lt: './ajaxFramework/ext-2.1/img/less_then.png',
	  eq: './ajaxFramework/ext-2.1/img/equals.png'
	};
Ext.grid.filter.StringFilter.prototype.icon = './ajaxFramework/ext-2.1/img/find.png';

/*  动态获取文件种类      */
var typeurl=Ext.get('typeurl').getValue();
var typestore = new Ext.data.JsonStore({
	fields: ['typeName'],
	url: typeurl
});
typestore.load();
	
var colModel = new Ext.grid.ColumnModel([		
		{header:'标题',dataIndex:'biaoti'},
		{header:'发文类型',dataIndex:'wentype'},		
		{header:'位置',dataIndex:'people',menuDisabled : true,width:25},
		{header:'状态',dataIndex:'zhuangtai',width:25},				
		{header:'操作',dataIndex:'operate',menuDisabled : true}
]);

var filters = new Ext.grid.GridFilters({
		 cleanParams: function(p) {  // 清除参数的方法，要保留PagingToolbar分页用的两个参数
		   //var regex = new RegExp("^" + this.paramPrefix + "\[[0-9]+\]");
		   for(var key in p) {
		      if( key != 'start' && key != 'limit' )
		   //if(regex.test(key)) {
		    delete p[key];
		            //}
		               }
          },
	     buildQuery: function(filters) {	
		  // filters 就是getFilterData返回的值, 代码中push入去的对象
		  var p = {};
		  for(var i=0, len=filters.length; i<len; i++) {
		      var f = filters[i];
		      
		      // 取得在GridFilters中定义的filters中的一个filter
		      var filter = this.getFilter( f.field );
		      // 取得传递到server的参数名称
		      var name = (filter.paramName ? filter.paramName : filter.dataIndex);
		      var value = (filter.paramValue ? filter.paramValue : f.data['value']);
				if (name=="wentype"){
					var i =value-1001;
					value=typestore.getAt(i).get('typeName');
				}
		      if( value != '' ) p[ name ] = value;
		  }
		  return p;
		   },	
		  filters:[
		 	{type: 'string',  dataIndex: 'biaoti'},
		 	{type: 'list',  dataIndex: 'wentype',options:[], store:typestore,labelField: 'typeName',single : true},
		 	{type: 'string',  dataIndex: 'zhuangtai'}
	]}); 

	var url = Ext.get('url').getValue();
	sort = new Ext.data.JsonStore({
		url:url,
		fields:['wentype','biaoti','people','zhuangtai','operate'],
		root:'root',
		totalProperty:'totalProperty'
	});
	var bbar = new Ext.PagingToolbar({
		pageSize:23,
		store:sort,
		displayInfo:true,
		plugins: filters,
		emptyMsg:'没有记录'
	});
	
	 grid = new Ext.grid.GridPanel({
		title:'流程跟踪',
		cm:colModel,
		renderTo:'topic-grid',
		store:sort,
		loadMask:true,
		height:$(window).height()-17,
		bbar:bbar,
		plugins: filters,
		viewConfig:{
			forceFit:true,
			getRowClass:function(record,rowIndex,p,ds){
				if(record.get('state') == '是')
				{
					
					return 'red-row';
				}
				else if(record.get('state') == '中止')
				{
					
					return 'yellow-row';
				}
			}
		}
	});
	sort.load({params:{start:0, limit: 23}});	
}




/**
	 * 中止一个流程
	 * @param {} id 流程ID
	 */
	function suspend(id){
		 Ext.MessageBox.show({
           title:'消息',
           msg: '是否执行此操作?',
           buttons: Ext.MessageBox.YESNO,
           fn: function(btn){
           	  if(btn == 'yes'){
           	  	    var url = Ext.get('basePath').getValue()+ 'tjsinfo/tjsoa/xingzhengfawen/shenpi.do?method=suspend';
					Ext.Ajax.request({
						url:url,
						params:{
							flowid:id
						},
						success:function(response, options){
							    var responseArray = Ext.util.JSON.decode(response.responseText);                                              
			                     if(responseArray.success==true){
			                        Ext.Msg.alert('信息','操作成功！',function(){
			                        	sort.reload({callback :function(){
			                        		grid.getView().refresh();	
			                        	}});										
			                        });			                     
			                     }
			                    else{
			                    	Ext.Msg.alert('信息','操作失败！');     
			                    } 
						}
					});
           	  }	
           },
           icon: Ext.MessageBox.QUESTION
       });
		
					
	}


	/**
	 * 重启一个流程
	 * @param {} id 流程ID
	 */
	function resume(id){
		 Ext.MessageBox.show({
           title:'消息',
           msg: '是否执行此操作?',
           buttons: Ext.MessageBox.YESNO,
           fn: function(btn){
           	  if(btn == 'yes'){
           	  	    var url = Ext.get('basePath').getValue()+ 'tjsinfo/tjsoa/xingzhengfawen/shenpi.do?method=resume';
					Ext.Ajax.request({
						url:url,
						params:{
							flowid:id
						},
						success:function(response, options){
							    var responseArray = Ext.util.JSON.decode(response.responseText);                                              
			                     if(responseArray.success==true){
			                        Ext.Msg.alert('信息','操作成功！',function(){
			                        	sort.reload({callback :function(){
			                        		grid.getView().refresh();	
			                        	}});										
			                        });			                     
			                     }
			                    else{
			                    	Ext.Msg.alert('信息','操作失败！');     
			                    } 
						}
					});
           	  }	
           },
           icon: Ext.MessageBox.QUESTION
       });
	}
	
	